package game.logic.rules;

import game.logic.Cup;
import game.logic.Table;

/**
 * Class that implements the standard pong win rule i.e. every cup on one side 
 * has been turned red.
 * @author Justin
 *
 */
public class DefaultWinRule extends Rule
{
	boolean teamWon;
	
	public DefaultWinRule(Table theTable)
	{
		super(theTable);
		teamWon = false;
	}
	
	public Object executeRule(Object[] parameters)
	{
		Table.TableSide side = null;
		Cup[] cups;
		if(parameters.length != 1)
		{
			System.err.println("Invalid number of arguments provided to this rule!");
			return false;
		}
		else if(parameters[0] instanceof Table.TableSide)
		{
			System.err.println("Invalid argument type provideed to this rule!");
			return false;
		}
		else
		{
			side = (Table.TableSide) parameters[0];
		}
		
		if(side == Table.TableSide.LEFT)
		{
			cups = getTable().getLeftCups();
		}
		else
		{
			cups = getTable().getRightCups();
		}
		
		/*
		 * Iterate over our list of cups.  If any cup is not turned off(turned on)
		 * then the winning condition has not yet been met so we return false.
		 * If we get to the end of the loop, then all of our cups are turned off and 
		 * we return true.
		 */
		for(Cup c: cups)
		{
			if(c.isOff() == false)
			{
				return false;
			}
		}
		
		return true;
	}
}
